package com.cqie.practicaltraining.config.exception.exception.handler;

import com.cqie.practicaltraining.config.result.R;
import com.cqie.practicaltraining.config.result.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.function.Supplier;

/**
 * 异常底层执行逻辑
 *
 * @author shineTan
 * @date 2022/12/26 9:25
 */
@Slf4j
public abstract class BaseThrowExceptionHandler {

    public static R exception(Throwable throwable, ResultCodeEnum resultCodeEnum, Supplier<String> supplier) {
        try {
            return R.Failed(resultCodeEnum.getCode(), supplier.get());
        } catch (Exception e) {
            log.error("UnKnown exception: ", throwable);
            return R.Failed(throwable.getMessage());
        }
    }
}
